package com.qf.bootdaily.service.impl;

import com.qf.bootdaily.entity.User;
import com.qf.bootdaily.mapper.UserMapper;
import com.qf.bootdaily.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;
    @Override
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS,rollbackFor = Exception.class)
    public User login(String name,String password) {
        User login = userMapper.login(name);
        if (Objects.nonNull(login)){
            if (Objects.equals(login.getPassword(),password)){
                return login;
            }
        }
        return null;
    }

    @Override
    public int insertSelective(User record) {

        return userMapper.insertSelective(record);
    }

    @Override
    public List<User> showAll() {
        return userMapper.showAll();
    }
}
